﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace lok3_map_builder
{
    class Tile : Sprite
    {
        public void Load(GraphicsDevice gd, Bitmap input, Microsoft.Xna.Framework.Color colorKey)
        {
            Microsoft.Xna.Framework.Color[] pixels = new Microsoft.Xna.Framework.Color[input.Width * input.Height];
            for (int y = 0; y < input.Height; y++)
            {
                for (int x = 0; x < input.Height; x++)
                {
                    System.Drawing.Color c = input.GetPixel(x, y);
                    pixels[(y * input.Height) + x] = new Microsoft.Xna.Framework.Color(c.R, c.G, c.B, c.A);
                }
            }

            for (int i = 0; i < input.Width * input.Height; i++) if (pixels[i] == colorKey) pixels[i].A = 0;


            mSpriteTexture = new Texture2D(gd, input.Width, input.Height, true, SurfaceFormat.Color);
            mSpriteTexture.SetData<Microsoft.Xna.Framework.Color>(pixels);
        }
    }
}
